package vn.edu.saigontech.ncms.web.system;

import vn.edu.saigontech.ncms.model.system.Bank;
import vn.edu.saigontech.ncms.model.system.BankAccount;
import vn.edu.saigontech.ncms.service.BankAccountService;
import vn.edu.saigontech.ncms.service.BankService;
import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidateBankAccountAction extends AbstractValidator {
	private String number;
	private Long bankId;
	
	@Override
	public String check() {
		if(Checker.isEmpty(this.number)) 
			this.sendKeyError("validator.required", "number");
		Bank bank = BankService.INSTANCE.findById(this.bankId);
		BankAccount account = BankAccountService.INSTANCE.findByNameNBank(this.number, bank);
		if(account != null) 
			this.sendKeyError("validator.exist", this.number);
		return this.toSuccess();
	}

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	public Long getBankId() {
		return bankId;
	}

	public void setBankId(Long bankId) {
		this.bankId = bankId;
	}
}